function [ output ] = pulseq( input )
%PULSEQ Summary of this function goes here
%  Detailed explanation goes here

kGap=16;
kMaxDragLen=16;
nstrips=0;
ilaststrip=-kGap;
draglen=0;

output=[];
for i = 1 : length(input)
    if input(i) == 0
        continue;
    end
    d = i-ilaststrip;
    if (d<kGap)
        draglen = draglen + d;
        if draglen > kMaxDragLen
            if nstrips > 0
                output=output(1:end-1); % remove the recent one
            end
            %%draglen = 0;
            nstrips = 0;
        else
            output(end) = output(end)*nstrips;
            nstrips=nstrips+1;
            output(end) = output(end) + i;
            output(end) = round(output(end)/nstrips);
        end            
    else            
        output=[output, i];
        draglen=0;
        nstrips=1;
    end
    ilaststrip=i;
end


